Skip to content

feat: add contacts table and conversation export#64

Open
archeren wants to merge 6 commits intoMartian-Engineering:mainfrom
archeren:main
Open

feat: add contacts table and conversation export#64
archeren wants to merge 6 commits intoMartian-Engineering:mainfrom
archeren:main

Conversation

@archeren
Copy link
Copy Markdown

@archeren archeren commented Mar 14, 2026

Summary

This PR adds peer tracking and conversation export functionality to LCM, enabling organized export of conversations by who you talked to.

Features

1. Database Schema

New contacts table:

CREATE TABLE contacts (
  peer_id TEXT PRIMARY KEY,
  peer_name TEXT,
  chat_type TEXT CHECK (chat_type IN ('dm', 'group'))
);

New columns in conversations table:

ALTER TABLE conversations ADD COLUMN peer_id TEXT REFERENCES contacts(peer_id);
ALTER TABLE conversations ADD COLUMN channel TEXT;

2. ContactStore

New store for managing contacts:

  • create() — Create or update a contact
  • get() — Get contact by peer_id
  • getAll() — List all contacts
  • update() — Update contact fields
  • delete() — Delete a contact

3. lcm_export Tool

Export conversations to markdown files organized by peer and date.

lcm_export --outputDir ./exports
lcm_export --peerId "user:ou_xxx"
lcm_export --chatType dm
lcm_export --from 2026-03-01 --to 2026-03-15

Output structure:

exports/
├── dm/
│   └── Alice/
│       └── 2026-03/
│           └── 2026-03-14.md
└── group/
    └── Project-Alpha/
        └── 2026-03/
            └── 2026-03-14.md

Message format:

[channel] 14:30 Alice: Hello, how are you?
[channel] 14:31 Assistant: I'm doing well, thanks!

4. Enhanced lcm_grep

Added peer filters to conversation search:

lcm_grep --pattern "hello" --peerId "user:ou_xxx"
lcm_grep --pattern "meeting" --chatType group
lcm_grep --pattern "bug" --channel feishu

5. Automatic Peer Extraction

Registered message_received hook to auto-extract peer info from inbound messages:

  • DMs: peer = sender (user:xxx)
  • Groups: peer = chat/group (chat:xxx)

No manual setup required — contacts are created automatically when messages arrive.

6. lcm_update_peer Tool (Manual Override)

Manually update peer info if needed:

lcm_update_peer --peerId "user:ou_xxx" --peerName "Alice" --channel feishu --chatType dm

Testing

  • Added 4 unit tests for export functionality
  • All 251 tests passing
  • Uses in-memory SQLite for isolated testing

Use Cases

  • Archive conversations organized by who you talked to
  • Search history filtered by peer, channel, or chat type
  • Export for analysis or migration to other systems
  • Audit trails with clear organization by contact

Breaking Changes

None. The schema additions are additive and backward-compatible.

Migration

Existing LCM databases will be automatically migrated on next startup with the new columns and contacts table.

Ubuntu added 6 commits March 14, 2026 23:13
- Add contacts table (peer_id, peer_name, chat_type)
- Add peer_id and channel columns to conversations table
- Create ContactStore for managing contacts
- Update ConversationStore to support peer_id and channel
- Add migration for existing databases

This enables tracking who conversations are with, and allows
exporting conversations organized by peer and date.
- Add export.ts module with exportConversations function
- Add lcm-export-tool.ts following LCM tool patterns
- Register lcm_export tool in plugin index
- Export format: [channel] time name: message
- Directory structure: dm/{peer}/YYYY-MM/YYYY-MM-DD.md
- Support filters: peerId, chatType, from, to

Usage: lcm_export --outputDir ./exports [--peerId xxx] [--chatType dm|group] [--from YYYY-MM-DD] [--to YYYY-MM-DD]
- Test DM conversation export to correct directory
- Test group conversation export
- Test peerId filtering
- Test handling of missing peer info
- Uses in-memory database, no effect on production
- Add --peerId, --channel, --chatType parameters to lcm_grep
- Update MessageSearchInput to include peer filters
- Update searchFullText, searchLike, searchRegex methods
- JOIN with conversations and contacts tables for filtering

Usage:
  lcm_grep --pattern 'hello' --peerId 'user:alice'
  lcm_grep --pattern 'meeting' --chatType group
  lcm_grep --pattern 'bug' --channel feishu
- Add updateConversationPeer method to LcmContextEngine
- Auto-creates/updates contact when peer info is provided
- Updates conversation with peer_id and channel
- Add lcm_update_peer tool for manual or automatic peer updates

Usage:
  lcm_update_peer --peerId 'user:alice' --peerName 'Alice' --channel feishu --chatType dm

Integration:
- OpenClaw can call this when receiving inbound metadata
- Can also be called manually to update peer info
- Register message_received hook in LCM plugin
- Auto-extract peer info from inbound metadata
- DM: peer is sender (user:xxx)
- Group: peer is chat/group
- Automatically populates contacts table on message receipt

This enables automatic contact creation without manual calls to lcm_update_peer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant